using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

namespace SunshineFarmWord
{
    public class PlayerWaitingState : PlayerFishingBaseState
    {
        // 等待时间最大值
        private float waitTimeMax = 3f;
        public PlayerWaitingState(PlayerStateMachine playerStateMachine) : base(playerStateMachine)
        {
        }

        #region base function 
        public override void Enter()
        {
            base.Enter();

            InitWaitingReusableData();

            //进行随机等待时间
            waitTimeMax = Random.Range(stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishWaitTimeMin, stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishWaitTimeMax);

            StartAnimation(stateMachine.Player.AnimationData.WaitingParameterHash);
        }

        public override void Exit()
        {
            base.Exit();

            //InitWaitingData();

            StopAnimation(stateMachine.Player.AnimationData.WaitingParameterHash);
        }

        public override void Update()
        {
            base.Update();

            CheckWaitTime();
        }
        #endregion

        #region 按键监听

        // 交互
        protected override void OnInteractStarted(InputAction.CallbackContext context)
        {
            base.OnInteractStarted(context);
            //退出钓鱼
            stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.IsFishingSustain = false;
            stateMachine.ChangeState(stateMachine.CaughtState);
        }
        #endregion



        #region Main function
        private void CheckWaitTime()
        {
            if (stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishWaitTime < waitTimeMax)
            {
                stateMachine.ReusableData.PlayerStatesData.PlayerFishingData.FishWaitTime += Time.deltaTime;
            }
            else
            {
                stateMachine.ChangeState(stateMachine.ReelingState);
            }
        }
        #endregion
    }
}
